fix: match Claude CLI's project-folder encoding (fixes #38, supersedes #37)#41
Merged
Merged
Conversation
…sidebar entries Switchboard's folder-name regex only replaced `/` and `_`, while the Claude CLI replaces every non-alphanumeric character (and applies a 200-char cap with a hash suffix on overflow). For project paths containing spaces, dots, backslashes, colons, etc., the two sides produced different folder names under ~/.claude/projects/, surfacing as undismissable duplicate projects in the sidebar. - Add encode-project-path.js mirroring the CLI's algorithm exactly (reverse-engineered from claude 2.1.126: /[^a-zA-Z0-9]/g, 200-char cap, (h<<5)-h+c|0 hash suffix on overflow). Deterministic and pure. - Mirror the encoder in public/utils.js for the renderer. - Route all 10 call sites through encodeProjectPath(). - Fix session-cache.js phantom-project bug: only insert a project entry after the archive filter passes, so folders whose sessions are all archived don't appear as empty undismissable projects in the sidebar. Fixes #38. Supersedes #37 (also covers Windows drive paths). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 4, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two bugs combined to produce undismissable duplicate project entries in the sidebar (#38). PR #37 partially addressed this for Windows drive paths; this PR fixes the root cause for all platforms by matching Claude CLI's encoding algorithm exactly.
Bug 1 — folder-name encoding mismatch
Switchboard's regex
replace(/[/_]/g, '-')only handled/and_. The Claude CLI normalizes every non-alphanumeric character and applies a 200-character cap with a deterministic hash suffix on overflow. So any path containing spaces, dots, backslashes (Windows), colons (Windows drive letters), or parentheses produced two different folder names — Switchboard's seed folder, and the CLI's actual session folder — both surfacing as the same project in the sidebar.Reverse-engineered the CLI's algorithm from
claude2.1.126:The hash is a Java-style
String.hashCodetruncated to int32. Pure and deterministic, so Switchboard now produces byte-identical folder names to the CLI for any project path.Bug 2 — phantom projects from archive filter ordering
In
session-cache.js:buildProjectsFromCache, the project entry was added toprojectMapbefore theif (!showArchived && s.archived) continuefilter ran. Folders whose sessions were all archived ended up as empty{ sessions: [] }entries in the sidebar, and the archive button'sif (sessions.length === 0) returnmade them undismissable. Fix: only insert intoprojectMapafter the filter passes.Changes
encode-project-path.js— single source of truth for the encoder (main process)public/utils.jsfor the renderermain.js,session-cache.js,schedule-ipc.js,public/app.js,public/dialogs.jsnow useencodeProjectPath()session-cache.jsarchive-filter ordering fixMigration note
Existing duplicate folders on disk from before this fix are left alone — auto-cleanup felt risky. Users with pre-existing dupes can
rm -rf ~/.claude/projects/<bad-folder-name>manually. New projects added after this fix will encode correctly and merge with whatever the CLI creates.Relationship to #37
#37 widened the regex to
[\\/:_]to cover Windows drive paths. This PR subsumes that fix —[^a-zA-Z0-9]covers\and:and everything else, and adds the missing 200-char cap + hash suffix branch. Recommend closing #37 in favor of this.Test plan
/Users/you/My Project) → folder created as-Users-you-My-Project, matches CLI whenclaudeis run theremsci-6.1-upgrade) → encodes consistently with CLIQ:\src\DevBox) → folder created asQ--src-DevBox, no ENOENTFixes #38.